package com.sservice.commonBusiness.controller.web;

import com.sservice.base.entity.dto.BaseResult;
import com.sservice.base.entity.dto.ListResult;
import com.sservice.base.entity.dto.Pagination;
import com.sservice.commonBusiness.service.CategoryService;
import com.sservice.commonBusiness.vo.CategoryVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;


/**
 * Created by byte_su@163.com on 2018/01/12.
 */
@Controller
@RequestMapping("/category1/")
public class Category1Controller {

    @Autowired
    CategoryService categoryService;

    @RequestMapping("list")
    @ResponseBody
    public ListResult list(CategoryVo categoryVo) {
        List<CategoryVo> list = categoryService.page(categoryVo);
        ListResult listResult = new ListResult(true, list);
        listResult.setPage(new Pagination(categoryVo.getPage(), categoryService.countByPage(categoryVo), categoryVo.getSize()));
        return listResult;
    }

    @RequestMapping("update3")
    @ResponseBody
    public BaseResult update(CategoryVo categoryVo) {
        return new BaseResult(true, String.valueOf(categoryService.updateByPrimaryKeySelective(categoryVo)), 200);
    }

    @RequestMapping("queryPlain")
    @ResponseBody
    public ListResult queryPlain(CategoryVo categoryVo) {
        List<CategoryVo> list = categoryService.queryPlainByPage(categoryVo);
        int count = categoryService.countPlainByPage(categoryVo);
        ListResult listResult = new ListResult(true, list);
        listResult.setPage(new Pagination(categoryVo.getPage(), count, categoryVo.getSize()));
        return listResult;
    }
}
